/**
 * @file   EventPacket.h
 * @author Djuro Drljaca (djurodrljaca@gmail.com)
 * @date   2014-04-26
 * @brief  DON packet object: Event
 *
 * Copyright 2014  Djuro Drljaca (djurodrljaca@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef DON_CORE_PACKET_EVENTPACKET_H
#define DON_CORE_PACKET_EVENTPACKET_H

#include <DON/Core/Packet/AbstractPacket.h>
#include <DON/Core/DataType/AbstractDataType.h>

namespace DON
{
namespace Core
{
namespace Packet
{

/**
 * @brief The EventPacket class
 */
class LIBDONQT4CORESHARED_EXPORT EventPacket : public AbstractPacket
{
public:
    /**
     * @brief Constructor
     */
    EventPacket();

    /**
     * @brief Constructor
     * @param source Packet's Source address
     * @param destination Packet's Destination address
     * @param sequence Sequence number
     * @param eventId Event ID
     * @param confirmationRequired Confirmation required flag
     */
    EventPacket(const quint16 source,
                const quint16 destination,
                const quint16 sequence,
                const quint16 eventId,
                const bool confirmationRequired);

    /**
     * @brief Copy constructor
     * @param other Object to be copied
     */
    EventPacket(const EventPacket &other);

    /**
     * @brief Destructor
     */
    ~EventPacket();

    /**
     * @brief Assignment operator
     * @param other Object to be copied
     * @return This object
     */
    EventPacket & operator=(const EventPacket &other);

    /**
     * @brief Checks if packet is valid
     * @retval true Packet is valid
     * @retval false Packet is not valid
     */
    bool isValid() const;

    /**
     * @brief Get event ID
     * @return Event ID
     */
    quint16 getEventId() const;

    /**
     * @brief Set event ID
     * @param eventId New event ID
     */
    void setEventId(const quint16 eventId);

    /**
     * @brief Get confirmation required flag
     * @return Confirmation required flag value
     */
    bool getConfirmationRequired() const;

    /**
     * @brief Set confirmation required flag
     * @param confirmationRequired New confirmation required flag value
     */
    void setConfirmationRequired(const bool confirmationRequired);

    /**
     * @brief Get event value value count
     * @return Event value value count
     */
    int getEventValueCount() const;

    /**
     * @brief Get event value value
     * @param index Index of the event value
     * @return Event value value at the selected index
     * @retval NULL Invalid index
     */
    const DataType::AbstractDataType * getEventValue(const int index) const;

    /**
     * @brief Set event value value at the selected index
     * @param eventValue Event value
     * @param index Index of the event value
     * @retval true Success
     * @retval false Error
     */
    bool setEventValue(const DataType::AbstractDataType &eventValue, const int index);

    /**
     * @brief Add event value value
     * @param eventValue New event value
     * @retval true Success
     * @retval false Error
     *
     * @note Event value value is added to the end of the event value list.
     */
    bool addEventValue(const DataType::AbstractDataType &eventValue);

    /**
     * @brief Remove event value value
     * @param index Index of the argument
     * @retval true Success
     * @retval false Error
     */
    bool removeEventValue(const int index) const;

    /**
     * @brief Remove all event value values
     */
    void removeAllEventValues();

    /**
     * @brief Get maximum number of event values
     * @return Maximum number of event values
     */
    static int getMaxEventValueCount();

private:
    /**
     * @brief Get the packet's payload data items
     * @param[out] ok Error status output (true --> success, false --> error)
     * @return List of payload data items
     */
    QList<QByteArray> getPayloadDataItems(bool *ok = NULL) const;

    class Private;
    Private * const d;
};

}
}
}

#endif // DON_CORE_PACKET_EVENTPACKET_H
